package com.atguigu.redisconfig;

import com.atguigu.constant.RedisConst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;

@Configuration
public class ShopMessageListener {
    @Autowired
    private RedisTemplate redisTemplate;

    //具体处理消息的方法
    public void receiveChannelMessage(String message) {
        //""24:1""
        if (!StringUtils.isEmpty(message)) {
            message = message.replaceAll("\"", "");
            String[] splitMessage = message.split(":");
            if (splitMessage.length == 2) {
                //splitMessage[0]是商品的skuId, splitMessage[1]是秒杀状态位
                redisTemplate.opsForValue().set(RedisConst.SECKILL_STATE_PREFIX + splitMessage[0], splitMessage[1]);
            }
        }

    }
}
